/*
 * @Author: error: git config user.name & please set dead value or install git
 * @Date: 2022-08-31 10:26:21
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-06-25 17:55:55
 * @FilePath: \stm32g431_AllRings\applications\eeprom.h
 * @Description:
 *
 * Copyright (c) 2022 by error: git config user.name && git config user.email & please set dead value or install git, All Rights Reserved.
 */
#ifndef __EEPROM_H
#define __EEPROM_H

#include <rtthread.h>
#include <board.h>
#include "rtdebug.h"

/* Exported types ------------------------------------------------------------*/

typedef struct
{
    uint8_t BUSY;
    uint8_t WRITE;
} _EEPROM;

/* Exported define ------------------------------------------------------------*/
// FT24C16����ַ
#define ADDR_FT24Cxx_Write 0xA0
// FT24C16д��ַ
#define ADDR_FT24Cxx_Read 0xA1

/* AT24C04/08A/16Aÿҳ��16���ֽ� */
#define EEPROM_PAGESIZE 128

#define I2Cx_TIMEOUT_MAX 300
/* Maximum number of trials for HAL_I2C_IsDeviceReady() function */
#define EEPROM_MAX_TRIALS 300
/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/

/* Exported variables --------------------------------------------------------*/
extern _EEPROM EEPROM;
extern I2C_HandleTypeDef hi2c1;
extern uint16_t page_addr[10];
/* Exported functions ------------------------------------------------------- */

void EEPROM_Routine(void);
void CALI_EEPROM_WRITE(void);
void EEPROM_READ(void);
void Can_IDSN_WRITE(void);
void Can_PARA_WRITE(void);

/* EEPROM ��д */
uint8_t EE_IIC_ReadByteFromSlave(uint16_t reg, uint8_t *buf);
uint8_t EE_EE_IIC_SendByteToSlave(uint16_t reg, uint8_t data);
uint8_t I2C_EE_PageWrite(uint8_t *buf, uint16_t reg, uint16_t l);
uint8_t I2C_EE_PageRead(uint8_t *buf, uint16_t reg, uint16_t l);

uint8_t I2C_EE_RANDOM_Write(uint8_t *buf, uint16_t reg, uint16_t l);

void I2C_EE_Full_erase(void);

#endif
